package model

import (
	"gorm.io/plugin/soft_delete"
	"time"
)

type BaseModel struct {
	ID        uint64                `gorm:"primarykey;comment:主键"`
	CreateAt  time.Time             `gorm:"column:create_time;autoCreateTime;comment:创建时间"`
	UpdateAt  time.Time             `gorm:"column:update_time;autoUpdateTime;comment:更新时间"`
	IsDeleted soft_delete.DeletedAt `gorm:"type:int(1);not null;softDelete:flag,DeletedAtField:DeletedAt;default:0;comment:0未删除1删除"`
	Status    int32                 `gorm:"type:int(1);not null;default:1;comment:0未发布1发布"`
	// 忽略该字段，- 表示无读写，-:migration 表示无迁移权限，-:all 表示无读写迁移权限
	//Children any `gorm:"-" json:"children"`
}

// 商品分类表
type Category struct {
	BaseModel
	Name     string `gorm:"type:varchar(40);not null;default:'';comment:分类名称"`
	Icon     string `gorm:"type:varchar(60);not null;default:'';comment:分类图标"`
	Img      string `gorm:"type:varchar(200);not null;default:'';comment:分类的封面"`
	Sorted   int32  `gorm:"type:int(1);not null;default:1;comment:排序"`
	IsIndex  bool   `gorm:"not null;default:0;comment:是否显示首页 1显示 0不显示"`
	ParentId uint64 `gorm:"bigint;not null;default:0;comment:父ID"`
}

func (c *Category) TableName() string {
	return "ksd_category"
}

// 广告表
type Banner struct {
	BaseModel
	Img    string `gorm:"type:varchar(200);not null;default:'';comment:图片"`
	Url    string `gorm:"type:varchar(200);not null;default:'';comment:跳转地址"`
	Sorted int32  `gorm:"type:int(1);not null;default:1;comment:排序"`
	SType  int32  `gorm:"type:int(1);not null;default:1;comment:1首页广告 2分类广告'"`
}

func (c *Banner) TableName() string {
	return "ksd_banner"
}

// 广告表
type Goods struct {
	BaseModel
	Name         string  `gorm:"type:varchar(100);not null;default:'';comment:商品名称"`
	Sn           string  `gorm:"type:varchar(60);not null;default:'';comment:商品编号"`
	CategoryId   uint64  `gorm:"type:bigint;not null;default:0;comment:商品分类"`
	CategoryName string  `gorm:"type:varchar(100);not null;default:'';comment:分类名称"`
	OnSale       bool    `gorm:"not null;default:true;comment:是否在售 1销售中 0 停售"`
	IsFree       bool    `gorm:"not null;default:true;comment:是否免费 1收费 0免费"`
	IsNew        bool    `gorm:"not null;default:false;comment:是否新品 1是0否"`
	IsHot        bool    `gorm:"not null;default:false;comment:是否热品 1是0否"`
	Desc         string  `gorm:"type:varchar(400);not null;default:'';comment:商品描述"`
	ViewCount    int32   `gorm:"type:int;not null;default:0;comment:点击数"`
	BuyNum       int32   `gorm:"type:int;not null;default:0;comment:购买数"`
	FavNum       int32   `gorm:"type:int;not null;default:0;comment:收藏数"`
	CommentNum   int32   `gorm:"type:int;not null;default:0;comment:评论数"`
	IsComment    bool    `gorm:"not null;default:true;comment:是否允许评论1允许0不允许"`
	SalePrice    float32 `gorm:"not null;default:0;comment:成交价格"`
	Price        float32 `gorm:"not null;default:0;comment:展示价格"`
	Img          string  `gorm:"type:varchar(200);not null;default:'';comment:封面"`
	Images       string  `gorm:"type:varchar(1000);not null;default:'';comment:图集"`
	ContentImgs  string  `gorm:"type:varchar(1000);not null;default:'';comment:内容图集"`
}

func (c *Goods) TableName() string {
	return "ksd_goods"
}
